package day_02_Thread;

import sun.awt.windows.ThemeReader;

public class selaTicket implements Runnable{
    private Integer ticketNum = 10;


    public void run(){

        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        while(true) {

            if(ticketNum<=0){
                System.out.println("票已经卖完");
                break;
            }
            synchronized (this) {
                if(ticketNum>0){
                ticketNum = ticketNum-1;
                System.out.println(Thread.currentThread().getName()+"抢倒票了，还剩"+ticketNum+"张票");
                }
            }
        }


    }





}
